//
//  LSAskForLeaveViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/1/22.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSAskForLeaveViewController.h"
#import "LSInfoCollectTableViewCell.h"
#import "LSDatePickViewController.h"
#import "NZKTextView.h"

#define FontSize 14

@interface LSAskForLeaveViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UITextViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *tableViewHeaderView;
@property (nonatomic, strong) UIView *tableViewFooterView;
@property (nonatomic, strong) NSArray *contentArray;

@property (nonatomic, strong) NZKTextView *contentTV;
@property (nonatomic, strong) UITextField *postTF;
@property (nonatomic, strong) UITextField *leaveTypeTF;
@property (nonatomic, strong) UITextField *leaveTimeLengthTF;
@property (nonatomic, strong) UITextField *leaveBeginTimeTF;
@property (nonatomic, strong) UITextField *leaveEndTimeTF;
@property (nonatomic, strong) UITextField *approveByTF;
@property (nonatomic, strong) UITextField *informToTF;

@property (nonatomic, assign) BOOL isHaveDian;
@end

static NSString *LSInfoCollectTableViewCellID = @"LSInfoCollectTableViewCellID";

@implementation LSAskForLeaveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"请假申请";
    self.isHaveDian = false;
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.tableViewHeaderView;
}

#pragma mark - 提交按钮点击事件
- (void)submitButtonClick {
    if ([self.contentTV.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请输入请假事由"];
        return;
    } else if ([self.leaveTypeTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择请假类型"];
        return;
    } else if ([self.leaveTimeLengthTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请输入请假时长"];
        return;
    } else if ([self.leaveBeginTimeTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择请假开始时间"];
        return;
    } else if ([self.leaveEndTimeTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择请假结束时间"];
        return;
    } else if ([self.approveByTF.text isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"请选择审批人"];
        return;
    }
    NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithDictionary:@{
                                                                                   @"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],
                                                                                   @"approveMain":self.contentTV.text,
                                                                                   @"leaveType":[ValidateUtils validateNull:self.leaveTypeTF.placeholder],
                                                                                   @"leave_duration":self.leaveTimeLengthTF.text,
                                                                                   @"leaveStartTime":self.leaveBeginTimeTF.text,
                                                                                   @"leaveEndTime":self.leaveEndTimeTF.text,
                                                                                   @"approve_id":[ValidateUtils validateNull:self.approveByTF.placeholder],
                                                                                   @"approve_name":[ValidateUtils validateNull:self.approveByTF.text]
                                                                                   }];
    if (![[ValidateUtils validateNull:self.postTF.placeholder] isEqualToString:@""]) [param setValue:[ValidateUtils validateNull:self.postTF.placeholder] forKey:@"approveDepart"];
    if (![[ValidateUtils validateNull:self.informToTF.placeholder] isEqualToString:@""]) {
        [param setValue:[ValidateUtils validateNull:self.informToTF.placeholder] forKey:@"sendBy"];
        [param setValue:[ValidateUtils validateNull:self.informToTF.text] forKey:@"sendName"];
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"GET" URL:AskForLeaveApply param:param completionHandler:^(id responseObject, NSError *connectionError) {
        [hud hideAnimated:true];
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                [MBProgressHUD showTipMessageInWindow:@"申请已提交"];
                WS
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [weakSelf.navigationController popViewControllerAnimated:true];
                });
            } else {
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:[responseObject objectForKey:@"message"]]];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"%@",connectionError.localizedDescription]];
        }
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LSInfoCollectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSInfoCollectTableViewCellID forIndexPath:indexPath];
    cell.leftLabel.text = self.contentArray[indexPath.row];
    [cell.leftLabel sizeToFit];
    if (indexPath.row == 0 || indexPath.row == 6) {
        cell.xingImageView.hidden = true;
    } else {
        cell.xingImageView.hidden = false;
    }
    
    for (UIView *subView in cell.contentView.subviews) {
        if ([subView isKindOfClass:UITextField.class]) {
            [subView removeFromSuperview];
        }
    }
    
    LSInfoCollectTableViewCell *currentCell = cell;
    if (indexPath.row == 0) {
        [currentCell.contentView addSubview:self.postTF];
        [self.postTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    } else if (indexPath.row == 1) {
        [currentCell.contentView addSubview:self.leaveTypeTF];
        [self.leaveTypeTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    } else if (indexPath.row == 2) {
        [currentCell.contentView addSubview:self.leaveTimeLengthTF];
        [self.leaveTimeLengthTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    } else if (indexPath.row == 3) {
        [currentCell.contentView addSubview:self.leaveBeginTimeTF];
        [self.leaveBeginTimeTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    } else if (indexPath.row == 4) {
        [currentCell.contentView addSubview:self.leaveEndTimeTF];
        [self.leaveEndTimeTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    } else if (indexPath.row == 5) {
        [currentCell.contentView addSubview:self.approveByTF];
        [self.approveByTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    } else if (indexPath.row == 6) {
        [currentCell.contentView addSubview:self.informToTF];
        [self.informToTF mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(currentCell.leftLabel.mas_right).with.offset(12);
            make.right.equalTo(currentCell.contentView.mas_right).with.offset(-15);
            make.top.equalTo(currentCell.contentView.mas_top).with.offset(8);
            make.bottom.equalTo(currentCell.contentView.mas_bottom);
        }];
    }
    
    return cell;
}

#pragma mark - 弹窗
- (void)showSelectControllerForTextField:(UITextField *)textField WithContentArray:(NSArray <NSDictionary *> *)contentArray showCode:(NSString *)showCode requestCode:(NSString *)requestCode {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (int i = 0; i < contentArray.count; i++) {
        [alertC addActionTarget:alertC title:contentArray[i][showCode] color:NAV_COLOR action:^(UIAlertAction *action) {
            textField.text = [ValidateUtils validateNull:contentArray[i][showCode]];
            textField.placeholder = [ValidateUtils validateNull:contentArray[i][requestCode]];
        }];
    }
    [alertC addCancelActionTarget:alertC color:NAV_COLOR title:@"取消"];
    [self presentViewController:alertC animated:true completion:nil];
}

- (void)showDateSelectControllerForTextField:(UITextField *)textField WithTitle:(NSString *)title {
    LSDatePickViewController *alertVC = [LSDatePickViewController alertControllerWithTitle:[NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n\n\n\n",title] message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 获取当前datePicker上面选择的时间
        NSDate *date = alertVC.datePicker.date;
        // NSLog(@"-----%@", date);
        // 创建时间格式化工具
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        if (textField == self.leaveBeginTimeTF) {
            if (![self.leaveEndTimeTF.text isEqualToString:@""]) {
                NSDate *endDate = [df dateFromString:self.leaveEndTimeTF.text];
                if ([date earlierDate:endDate] == endDate) {
                    [MBProgressHUD showTipMessageInWindow:@"请假开始时间不可晚于请假结束时间"];
                    return;
                }
            }
        } else if (textField == self.leaveEndTimeTF) {
            if (![self.leaveBeginTimeTF.text isEqualToString:@""]) {
                NSDate *beginDate = [df dateFromString:self.leaveBeginTimeTF.text];
                if ([date earlierDate:beginDate] == date) {
                    [MBProgressHUD showTipMessageInWindow:@"请假结束时间不可早于请假开始时间"];
                    return;
                }
            }
        }
        NSString *str = [df stringFromDate:date];
        textField.text = [NSString stringWithFormat:@"%@",str];
        textField.backgroundColor = UIColor.whiteColor;
    }];
    [alertVC addAction:cancelAction];
    [alertVC addAction:okAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)requestListForTextField:(UITextField *)textField withURLString:(NSString *)URLString andParam:(NSDictionary *)param listCode:(NSString *)listCode showCode:(NSString *)showCode requestCode:(NSString *)requestCode doAppend:(BOOL)append {
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:URLString param:param completionHandler:^(id responseObject, NSError *connectionError) {
        if (!connectionError) {
            NSLog(@"返回数据----%@",responseObject);
            NSArray *objArray = [responseObject objectForKey:listCode];
            if (objArray && objArray.count > 0) {
                NSMutableArray *objArrayM = [[NSMutableArray alloc] initWithArray:objArray];
                if (append) [objArrayM insertObject:@{showCode : @"--请选择--",requestCode : @""} atIndex:0];
                [self showSelectControllerForTextField:textField WithContentArray:objArrayM showCode:showCode requestCode:requestCode];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:[NSString stringWithFormat:@"%@",connectionError.localizedDescription]];
        }
    }];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == self.postTF) {
        // 请求职务列表
        [self requestListForTextField:self.postTF withURLString:OASjzd andParam:@{@"typeGroupName":@"userDuty",@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token]} listCode:@"obj" showCode:@"typename" requestCode:@"typecode" doAppend:false];
        return false;
    } else if (textField == self.leaveTypeTF) {
        // 请求请假类型列表
        [self requestListForTextField:self.leaveTypeTF withURLString:OASjzd andParam:@{@"typeGroupName":@"leave",@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token]} listCode:@"obj" showCode:@"typename" requestCode:@"typecode" doAppend:false];
        return false;
    } else if (textField == self.leaveBeginTimeTF) {
        // 弹出请假开始时间选择框
        [self showDateSelectControllerForTextField:self.leaveBeginTimeTF WithTitle:@"请选择请假开始时间"];
        return false;
    } else if (textField == self.leaveEndTimeTF) {
        // 弹出请假结束时间选择框
        [self showDateSelectControllerForTextField:self.leaveEndTimeTF WithTitle:@"请选择请假结束时间"];
        return false;
    } else if (textField == self.approveByTF) {
        // 请求审批人姓名列表
        [self requestListForTextField:self.approveByTF withURLString:UserList andParam:@{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token]} listCode:@"data" showCode:@"realname" requestCode:@"username" doAppend:false];
        return false;
    } else if (textField == self.informToTF) {
        // 请求抄送人姓名列表
        [self requestListForTextField:self.informToTF withURLString:UserList andParam:@{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token]} listCode:@"data" showCode:@"realname" requestCode:@"username" doAppend:true];
        return false;
    }
    return true;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if (([ValidateUtils isInputRuleNotBlank:text] && ![ValidateUtils hasSpecialString:text]) || [text isEqualToString:@""]) {//当输入符合规则和退格键时允许改变输入框
        return YES;
    } else {
        if (text.length == 0 || [text isEqualToString:@""]) return TRUE;
        if (textView.text.length > 119) return FALSE;
        return TRUE;
    }
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (string.length == 0 ||  [string isEqualToString:@""]) return true;// 如果是删除字符，肯定是要通过的
    /*
     * 不能输入.0-9以外的字符。
     * 设置输入框输入的内容格式
     * 只能有一个小数点
     * 小数点后最多能输入两位
     * 如果第一位是.则前面加上0.
     * 如果第一位是0则后面必须输入点，否则不能输入。
     */
    
    // 判断是否有小数点
    if ([textField.text containsString:@"."]) {
        self.isHaveDian = YES;
    }else{
        self.isHaveDian = NO;
    }
    if (string.length > 0) {
        //当前输入的字符
        unichar single = [string characterAtIndex:0];
        // 不能输入.0-9以外的字符
        if (!((single >= '0' && single <= '9') || single == '.'))
        {
            //            [MBProgressHUD bwm_showTitle:@"您的输入格式不正确" toView:self hideAfter:1.0];
            return NO;
        }
        
        // 只能有一个小数点
        if (self.isHaveDian && single == '.') {
            //            [MBProgressHUD bwm_showTitle:@"最多只能输入一个小数点" toView:self hideAfter:1.0];
            return NO;
        }
        
        // 如果第一位是.则前面加上0.
        if ((textField.text.length == 0) && (single == '.')) {
            textField.text = @"0";
        }
        
        // 如果第一位是0则后面必须输入点，否则不能输入。
        if ([textField.text hasPrefix:@"0"]) {
            if (textField.text.length > 1) {
                NSString *secondStr = [textField.text substringWithRange:NSMakeRange(1, 1)];
                if (![secondStr isEqualToString:@"."]) {
                    //                    [MBProgressHUD bwm_showTitle:@"第二个字符需要是小数点" toView:self hideAfter:1.0];
                    return NO;
                }
            }else{
                if (![string isEqualToString:@"."]) {
                    //                    [MBProgressHUD bwm_showTitle:@"第二个字符需要是小数点" toView:self hideAfter:1.0];
                    return NO;
                }
            }
        }
        
        // 小数点后最多能输入两位
        if (self.isHaveDian) {
            NSRange ran = [textField.text rangeOfString:@"."];
            // 由于range.location是NSUInteger类型的，所以这里不能通过(range.location - ran.location)>2来判断
            if (range.location > ran.location) {
                if ([textField.text pathExtension].length > 1) {
                    //                    [MBProgressHUD bwm_showTitle:@"小数点后最多有两位小数" toView:self hideAfter:1.0];
                    return NO;
                }
            }
        }
    }
    if (range.length == 1 && string.length == 0) {
        return YES;
    } else {
        //否则返回yes,不限制其他textfield
        if (textField == self.leaveTimeLengthTF && textField.text.length >= 5) {
            textField.text = [textField.text substringToIndex:5];
            return NO;
        }
    }
    return YES;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (NSArray *)contentArray {
    if (!_contentArray) {
        _contentArray = @[@"职务：",@"请假类型：",@"请假时长：",@"请假开始时间：",@"请假结束时间：",@"审批人姓名：",@"抄送人姓名："];
    }
    return _contentArray;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight)];
        _tableView.separatorInset = UIEdgeInsetsZero;
        _tableView.backgroundColor = hexColor(eeeeee);
        UIView *tableViewFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
        UIButton *submitButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 30, ScreenWidth-30, 40)];
        [submitButton setTitle:@"提交" forState:UIControlStateNormal];
        [submitButton setTitleColor:hexColor(ffffff) forState:UIControlStateNormal];
        submitButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:14];
        submitButton.backgroundColor = hexColor(FDBB2C);
        submitButton.layer.cornerRadius = 4;
        submitButton.layer.masksToBounds = true;
        [submitButton addTarget:self action:@selector(submitButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [tableViewFooterView addSubview:submitButton];
        _tableView.tableFooterView = tableViewFooterView;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:LSInfoCollectTableViewCell.class forCellReuseIdentifier:LSInfoCollectTableViewCellID];
    }
    return _tableView;
}

- (UIView *)tableViewHeaderView {
    if (!_tableViewHeaderView) {
        _tableViewHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 120+35)];
        _tableViewHeaderView.backgroundColor = hexColor(ffffff);
        [_tableViewHeaderView addSubview:self.contentTV];
        UIImageView *xingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, 11, 35)];
        xingImageView.contentMode = UIViewContentModeCenter;
        xingImageView.image = [UIImage imageNamed:@"xinhao"];
        [_tableViewHeaderView addSubview:xingImageView];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, ScreenWidth-40, 35) andText:@"请假事由：" andTextColor:hexColor(333333) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:14] andTextAlignment:NSTextAlignmentLeft];
        [_tableViewHeaderView addSubview:label];
    }
    return _tableViewHeaderView;
}

- (NZKTextView *)contentTV {
    if (!_contentTV) {
        _contentTV = [[NZKTextView alloc] initWithFrame:CGRectMake(15, 35, ScreenWidth-30, 120)];
        _contentTV.layer.cornerRadius = 4;
        _contentTV.layer.masksToBounds = true;
        _contentTV.layer.borderWidth = 1;
        _contentTV.layer.borderColor = UIColor.grayColor.CGColor;
        _contentTV.delegate = self;
        _contentTV.placeHolder = @"限制120字以内";
    }
    return _contentTV;
}

- (UITextField *)postTF {
    if (!_postTF) {
        _postTF = [[UITextField alloc] init];
        _postTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        UIImageView *postTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
        postTFRightViewImageView.contentMode = UIViewContentModeCenter;
        postTFRightViewImageView.image = [UIImage imageNamed:@"kuang_xiala"];
        _postTF.rightView = postTFRightViewImageView;
        _postTF.rightViewMode = UITextFieldViewModeAlways;
        _postTF.delegate = self;
    }
    return _postTF;
}

- (UITextField *)leaveTypeTF {
    if (!_leaveTypeTF) {
        _leaveTypeTF = [[UITextField alloc] init];
        _leaveTypeTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        UIImageView *leaveTypeTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
        leaveTypeTFRightViewImageView.contentMode = UIViewContentModeCenter;
        leaveTypeTFRightViewImageView.image = [UIImage imageNamed:@"kuang_xiala"];
        _leaveTypeTF.rightView = leaveTypeTFRightViewImageView;
        _leaveTypeTF.rightViewMode = UITextFieldViewModeAlways;
        _leaveTypeTF.delegate = self;
    }
    return _leaveTypeTF;
}

- (UITextField *)leaveTimeLengthTF {
    if (!_leaveTimeLengthTF) {
        _leaveTimeLengthTF = [[UITextField alloc] init];
        _leaveTimeLengthTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        _leaveTimeLengthTF.delegate = self;
        _leaveTimeLengthTF.placeholder = @"例如1（小时）";
        _leaveTimeLengthTF.keyboardType = UIKeyboardTypeDecimalPad;
    }
    return _leaveTimeLengthTF;
}

- (UITextField *)leaveBeginTimeTF {
    if (!_leaveBeginTimeTF) {
        _leaveBeginTimeTF = [[UITextField alloc] init];
        _leaveBeginTimeTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        UIImageView *leaveBeginTimeTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
        leaveBeginTimeTFRightViewImageView.contentMode = UIViewContentModeCenter;
        leaveBeginTimeTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
        _leaveBeginTimeTF.rightView = leaveBeginTimeTFRightViewImageView;
        _leaveBeginTimeTF.rightViewMode = UITextFieldViewModeAlways;
        _leaveBeginTimeTF.delegate = self;
    }
    return _leaveBeginTimeTF;
}

- (UITextField *)leaveEndTimeTF {
    if (!_leaveEndTimeTF) {
        _leaveEndTimeTF = [[UITextField alloc] init];
        _leaveEndTimeTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        UIImageView *leaveEndTimeTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
        leaveEndTimeTFRightViewImageView.contentMode = UIViewContentModeCenter;
        leaveEndTimeTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
        _leaveEndTimeTF.rightView = leaveEndTimeTFRightViewImageView;
        _leaveEndTimeTF.rightViewMode = UITextFieldViewModeAlways;
        _leaveEndTimeTF.delegate = self;
    }
    return _leaveEndTimeTF;
}

- (UITextField *)approveByTF {
    if (!_approveByTF) {
        _approveByTF = [[UITextField alloc] init];
        _approveByTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        UIImageView *approveByTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
        approveByTFRightViewImageView.contentMode = UIViewContentModeCenter;
        approveByTFRightViewImageView.image = [UIImage imageNamed:@"kuang_xiala"];
        _approveByTF.rightView = approveByTFRightViewImageView;
        _approveByTF.rightViewMode = UITextFieldViewModeAlways;
        _approveByTF.delegate = self;
    }
    return _approveByTF;
}

- (UITextField *)informToTF {
    if (!_informToTF) {
        _informToTF = [[UITextField alloc] init];
        _informToTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:FontSize];
        UIImageView *informToTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 44-8, 44-8)];
        informToTFRightViewImageView.contentMode = UIViewContentModeCenter;
        informToTFRightViewImageView.image = [UIImage imageNamed:@"kuang_xiala"];
        _informToTF.rightView = informToTFRightViewImageView;
        _informToTF.rightViewMode = UITextFieldViewModeAlways;
        _informToTF.delegate = self;
    }
    return _informToTF;
}

@end
